#include<iostream>
#include<cstdio>
using namespace std;
int t,n,m,l,v,ans,w[100001],s[100001],lst;
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>t;
    while(t--)
    {
        cin>>n>>m>>l>>v;ans=0;
        for(int i=1,ww;i<=n;i++) cin>>w[i]>>s[i]>>ww;
        for(int i=1;i<=m;i++) cin>>lst;
        for(int i=1;i<=n;i++) if(w[i]<=lst&&s[i]>v) ans++;
        if(ans==0) m++;
        cout<<ans<<" "<<max(2,m)-1<<endl;
    }
    return 0;
}
